package com.qfx.modules.system.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfx.modules.system.entity.SysUser;
import com.qfx.modules.system.service.SysUserSer;

@Controller
@RequestMapping("sysTest")
public class SysUserCtl {
	@Autowired
	HttpServletRequest request;
	@Autowired
	SysUserSer sysUserSer;
	
	/**
	 * <h5>功能:跳转到测试表列表页面</h5>
	 * 
	 * @return 
	 */
	@RequestMapping("list/view")
	public String listView(){
		return "sys/user/list";
	}
	
	/**
	 * <h5>功能:跳转到测试表新增页面</h5>
	 * 
	 * @return 
	 */
	@RequestMapping("add/view")
	public String addView(){
		return "sys/user/add";
	}
	
	/**
	 * <h5>描述:跳转到测试表编辑页面</h5>
	 * 
	 * @param sysUser
	 * @return 
	 */
	@RequestMapping("edit/view")
	public String editView(SysUser sysUser){
		request.setAttribute("sysUser", sysUser);
		
		return "sys/user/edit";
	}
	

	/**
	 * <h5>描述:获取测试表列表数据</h5>
	 * 
	 * @param sysUser
	 * @return 
	 */
	@RequestMapping("list")
	@ResponseBody
	public String list(SysUser sysUser) {
		List<SysUser> sysUserList = sysUserSer.list(new QueryWrapper<SysUser>());
		
		return JSONObject.toJSONString(sysUserList);
	}
	
	/**
	 * <h5>功能:新增测试表</h5>
	 * 
	 * @param sysUser
	 * @return 
	 */
	@RequestMapping("add")
	@ResponseBody
	public String add(SysUser sysUser){
		boolean flag = sysUserSer.save(sysUser);
		
		return JSONObject.toJSONString(flag);
	}
	
	/**
	 * <h5>功能:编辑测试表</h5>
	 * 
	 * @param sysUser
	 * @return 
	 */
	@RequestMapping("edit")
	@ResponseBody
	public String edit(SysUser sysUser){
		boolean flag = sysUserSer.updateById(sysUser);
		
		return JSONObject.toJSONString(flag);
	}
	
	/**
	 * <h5>功能:删除测试表</h5>
	 * 
	 * @param String
	 * @return 
	 */
	@RequestMapping("del")
	@ResponseBody
	public String del(String id){
		boolean flag = sysUserSer.removeById(id);
		
		return JSONObject.toJSONString(flag);
	}
}
